#include "object.h"
#include <SDL_gfxPrimitives.h>

/*******************************
Default constructor
*******************************/
Object::Object()
{
	position = Vect2D(0,0);
	speed = Vect2D(0,0);
	health = 1;
	border = 1;
	remove = false;

	sprite = NULL;
}

/********************************
void Draw(...)
The default method of drawing object,
draws the sprite to the screen with the
set src_rect as the source rectangle.
********************************/
void Object::Draw(SDL_Surface* screen, const Vect2D& offset)
{
	Vect2D rel_position = position - offset;

	SDL_Rect dest_rect;
	dest_rect.x = rel_position.Get_x() - src_rect.w/2;
	dest_rect.y = rel_position.Get_y() - src_rect.h/2;

	SDL_BlitSurface(sprite, &src_rect, screen, &dest_rect);
}

/*************************
void Draw_border(...)
Draws the borders of the object
to the screen, representing a
kind of wireframe.
**************************/
void Object::Draw_border(SDL_Surface* screen, const Vect2D& offset, int color)
{
	Vect2D rel_position = position - offset;

	SDL_Rect dest_rect;
	dest_rect.x = rel_position.Get_x() - src_rect.w/2;
	dest_rect.y = rel_position.Get_y() - src_rect.h/2;

	aacircleColor(screen, position.Get_x(), position.Get_y(), border, color);
}

/******************************
void Hit(int)
The object is hit with damage.
If health dropes bellow 0,
the object is removed.

******************************/
void Object::Hit(int damage)
{
	health -= damage;
	if(health <= 0)
	{
		health = 0;
		Set_remove();
	}
}

/*****************************
void Set_remove()
Default Set_remove method.
*****************************/
void Object::Set_remove()
{
	remove = true;
}
